
* +++++++++++++++++++++
* FIGURE A18: 
* CORRELATIONS COVARS
* AND INTEGRATION
* +++++++++++++++++++++

* load data
use "${data_derived}/regional_analysis_data.dta",clear

qui: su log_frac_syr_tot_2010, d
replace log_frac_syr_tot_2010 = `r(min)' if log_frac_syr_tot_2010 ==. 

* select explanatory variables for plots
local demo "share_female avg_age"
local economy "frac_emp_train_any_syria log_pos_per_app_post log_unemp_tot2014_per_pop log_avg_inc" 
local crime "log_cases_per_pop_vio_cr_2014 log_cases_per_pop_theft_2014 log_cases_per_pop_2014"
local politics "log_frac_voted_2014 afd_2014_dev_st log_frac_christian"
local environment "pct_empty_flats log_pop_dens_2018"
local foreign "log_frac_for_tot_2019 log_frac_for_tot_2010 log_frac_syr_tot_2019 log_frac_syr_tot_2010"
local integration_efforts "log_clubs_per_syr per_pop_proasyl_groups log_per_syr_cours_compl_15_19"
local explan_vars "`integration_efforts' `foreign' `politics' `crime' `economy' `environment' `demo'"
local breaks "3 7 10 13 17 19"

* run correlations
gen integration = log(n_frnd_nat_lcl_sy_avg_re)
local i = 1
gen c_integration = .
gen c_st_integration = .
gen v_integration = ""
gen l_integration = ""
local breaks_new ""
qui: areg integration [w=n_frnd_nat_lcl_sy_n], absorb(state)
predict r_integration, r
local j=1
foreach e in `explan_vars' {
	qui: corr integration `e' [w=n_frnd_nat_lcl_sy_n]
	replace c_integration = `r(rho)' in `i'
	replace v_integration = "`e'" in `i'
	local lab: variable label `e'
	replace l_integration = "`lab'" in `i'
	qui: areg `e' if integration != . [w=n_frnd_nat_lcl_sy_n], absorb(state)
	predict r_`e', r
	qui: corr r_integration r_`e' [w=n_frnd_nat_lcl_sy_n]
	replace c_st_integration = `r(rho)' in `i'
	foreach b in `breaks' {
		if `i' == `b'+1*`j'-1 {
			local ++i
			local b_new = `b'+1*`j'
			local breaks_new "`breaks_new' `b_new'"
			local ++j
		}
	}
	local ++i 
}

* make correlation plot
gen x_1 = _n if c_integration !=. 
tw (scatter x_1 c_integration, msymbol(diamond) mcolor("227 26 28")) ///
	(scatter x_1 c_st_integration, msymbol(triangle) mcolor("28 134 238")), ///
	xline(0, lpattern(dash)) xlabel(-0.5(0.25)0.5) ///
	ytitle("") yline(`breaks_new', lpattern(dash) lcolor(gs8)) ///
	ylabel(1 "Log Integr.-Sports Clubs per Syr" 2 "Pro-Immigr. Groups per Pop" /// 
		3 "Log Integr. Courses per Syr" 5 "Log % Foreign 2019" ///
		6 "Log % Foreign 2010" 7 "Log % Syrians 2019" 8 "Log % Syrians 2010" ///
		10 "Log % Voted 2014" ///
		11 "% AfD 2014" 12 "Log % Christian" 14 "Log Violent Crimes 2014" 15 "Log Thefts 2014" ///
		16 "Log All Crimes 2014" 18 "Syrians Employed / in Train." ///
		19 "Log Train. Positions per Applicant" 20 "Log % Unemployed" /// 
		21 "Log Average Income" 23 "% Empty Flats" 24 "Log Pop Density 2018" ///
		26 "% Female" 27 "Avg. Age", labsize(small)) ///
	legend(order(1 "Raw" 2 "W/ State FE") col(3) ///
	pos(6) ring(6)) ysize(8) xsize(10)
graph export "${output}/corrplot_combined_all_vars_raw_state_fe_log.png", replace width(3000) 
 